<% link_to @computer, :class => "ui-state-default ui-corner-all dialog_link" do %>
			<span class="ui-icon ui-icon-search"></span>View
	<% end %>&nbsp;
	<% link_to computers_path, :class => 'ui-state-default ui-corner-all dialog_link' do %>
		<span class="ui-icon ui-icon-arrowreturnthick-1-w"></span>Back
	<% end %>
<h1>Editing computer</h1>

<% form_for(@computer) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :name %>
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :os %>
    <%= f.text_field :os %>
  </p>
  <p>
    <%= f.label :mac_address %>
    <%= f.text_field :mac_address %>
  </p>
  <p>
    <%= f.label :ip_address %>
    <%= f.text_field :ip_address %>
    <%= image_tag "ajax-loader.gif", :id=>"wait_icon", :style=>"display:none" %>
    <span id="computerStatusImg">
	    <%if @computer.status == 0%>
	    	<%= image_tag('circle_Red.png') %>
	    <%elsif @computer.status == 1%>
	    	<%= image_tag('circle_Green.png') %>
	    <%elsif @computer.status == 2%>
	    	<%= image_tag('circle_Orange.png') %>
	    <%end%>
    </span>
  </p>
  <p>
    <%= f.label :start_date %>
    <%= f.date_select :start_date %>
  </p>
  <p>
    <%= f.label :status %>
    <%= f.select(:status, Computer::COMPUTER_STATUS.map {|c| [c[1], c[0]] }, :selected => @computer.status)%>
  </p>
  <p>
    <%= f.label :room_id %>
    <% rooms = Room.all %>
    <%= f.select(:room_id, rooms.collect {|c| ["#{c.company.name} : #{c.code}", c.id] }, :selected => @computer.room_id)%>
  </p>
  <p>
    <%= f.label :network_id %>
    <% networks = Network.all %>
    <%= f.select(:network_id, networks.collect {|c| [c.name, c.id] }, :selected => @computer.network_id, :include_blank => true)%>
  </p>

  <p>
  <h2>Operations :</h2>
  <table border="2">
  	<tr class="ui-state-default">
  	  <th>Available</th>
  	  <th>Belongs to me</th>
  	</tr>
  	<tr>
  	  <td id='trash_operation'>
	     <% Operation.all.each do |operation| %>
      	   <%if !@computer.operations.include?(operation)%>
		     <%= render :partial => 'computers/computer_operation', :locals => {:operation => operation}%>
      	   <%end%>
		 <% end %>
	  </td>
	  <td id='container_operation'>
		<% Operation.all.each do |operation| %>
			<%if @computer.operations.include?(operation)%>
			  <%= render :partial => 'computers/computer_operation', :locals => {:operation => operation}%>
			<%end%>
		<%end%>
	  </td>
	</tr>
  </table>
  <%= drop_receiving_element('trash_operation',
    :accept => "dragable",
    :with   => "'operation_id=' + (element.id.split('_').last()) + '&computer_id=#{@computer.id.to_s}'",
    :url    => {:action=>:delete_operation}
  )%>
  <%= drop_receiving_element('container_operation',
    :accept => "dragable",
    :with   => "'operation_id=' + (element.id.split('_').last()) + '&computer_id=#{@computer.id.to_s}'",
    :url    => {:action=>:add_operation}
  )%>
  </p>
  
  <p>
  <h2>Contacts :</h2>
  <table border="2">
  	<tr class="ui-state-default">
  	  <th>Available</th>
  	  <th>Belongs to me</th>
  	</tr>
  	<tr>
  	  <td id='trash_contact'>
	     <% Contact.all.each do |contact| %>
      	   <%if !@computer.contacts.include?(contact)%>
	     	 <%= render :partial => 'computers/computer_contact', :locals => {:contact => contact}%>
      	   <%end%>
		 <% end %>
	  </td>
	  <td id='container_contact'>
		<% Contact.all.each do |contact| %>
			<%if @computer.contacts.include?(contact)%>
	      	  <%= render :partial => 'computers/computer_contact', :locals => {:contact => contact}%>
			<%end%>
		<%end%>
	  </td>
	</tr>
  </table>
  <%= drop_receiving_element('trash_contact',
    :accept => "dragable",
    :with   => "'contact_id=' + (element.id.split('_').last()) + '&computer_id=#{@computer.id.to_s}'",
    :url    => {:action=>:delete_contact}
  )%>
  <%= drop_receiving_element('container_contact',
    :accept => "dragable",
    :with   => "'contact_id=' + (element.id.split('_').last()) + '&computer_id=#{@computer.id.to_s}'",
    :url    => {:action=>:add_contact}
  )%>
  </p>
  
  <p>
    <%= f.submit 'Update' %>
  </p>
<% end %>


<%= observe_field :computer_ip_address,
  :url=>{:action=>:validateIp},  
  :before => "Element.toggle('wait_icon')",
  :complete => "Element.toggle('wait_icon')",
  :with => "'ip='+escape(value)"
%>

<%= observe_field :computer_network_id,
  :url=>{:controller => :computers, :action=>:get_rooms},
  :with => "'network_id='+escape(value)"
%>

<%= observe_field :computer_room_id,
  :url=>{:controller => :computers, :action=>:get_networks},
  :with => "'room_id='+escape(value)"
%>

	<% link_to @computer, :class => "ui-state-default ui-corner-all dialog_link" do %>
			<span class="ui-icon ui-icon-search"></span>View
	<% end %>&nbsp;
	<% link_to computers_path, :class => 'ui-state-default ui-corner-all dialog_link' do %>
		<span class="ui-icon ui-icon-arrowreturnthick-1-w"></span>Back
	<% end %>
